<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    
 public function login(){
      $this->display();
    }

      public function checkLogin(){
        $code=I('post.verify');
        if(!$this->check_verify($code)){
            $this->error('验证码错误');
        }else{

        $spadmin=$_POST['spadmin_name'];
        $sppassword=$_POST['sppassword'];
        //dump($name);
        //dump($password);
        $spadminModel=M('superadmin');
        
        $result=$spadminModel->where(array('spadmin_name'=>$spadmin,'sppassword'=>$sppassword))->find(); // 登陆，判断是否有数据且一样
        //dump($result);
        if($result){
             session('[start]'); // 启动session
             //session('flag',"logok"); 
             session('spadmin_name',"$spadmin_name");
             session('sppassword',"$sppassword");

            $this->success('登陆成功','../Index/superadmin');//设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
            } else {
             $this->error('帐号密码错误'); //错误页面的默认跳转页面是返回前一页，通常不需要设置
            }
        }

    }

/*2.俱乐部管理员登录*/

public function checkLoginadmin(){
        $code=I('post.verify');  //获取用户在表单中输入的验证码字符串
    if(!$this->check_verify($code))$this->error('验证码错误'); //调用check_verify函数，将用户输入的验证码加密处理后和Session中已存的验证码进行比较

        $adminmodel=M('admin');
        
         //实例化diuba_users表
        $map   =   array();
        $map['admin_name'] =trim(I('post.admin_name'));//获取用户输入的手机号
        $map['admin_pass']  =md5(trim(I('post.admin_pass')));
       //获取用户输入的密码，并用md5加密
        $res=$adminmodel->where($map)->find();
       // var_dump($res);
        if($res==null){
            $this->error('账号或密码错误');
        }else{
        
        $_SESSION['admin_name']=$map['admin_name'];
        $_SESSION['club_id']=$res['club_id'];       
        $_SESSION['alias']=$res[0]["admin_name"];
       
        redirect(U('Adminclub/Aclublist'));
        }
        }


  public function exitLog(){
        session('[destroy]'); // 销毁session
        session('admin_name',null);
        session('admin_pass',null);
        $this->success('退出成功','../index/index');
    }



  public function count(){
             $users = M('users');
            $count1 = $users->count();
            $this->count1 = $count1;
           
            $this->display();
       
     }




  public function logout(){
        session('[destroy]'); // 销毁session
        session('name',null);
        session('password',null);
        $this->success('注销成功','../index/index');
    }


    public function verify(){
        ob_clean();//清空缓存
        $Verify = new \Think\Verify();//调用验证码类实例化对象

        $Verify->useImgBg = true; 
        $Verify->fontSize = 25;
        $Verify->length = 3;
        $Verify->codeSet = '0123456789';
        $Verify->useCurve = false;
        $Verify->entry();//输出验证码图片，并将验证码加密处理后放到Session中
    }



  function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }








}